/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.tabbedproperties.section;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.uml2.uml.ObjectNode;

import com.cea.papyrus.core.tabbedproperties.PropertyViewSection;
import com.cea.papyrus.tabbedproperties.composites.StateComposite;
import com.cea.papyrus.umlutils.Element;

/**
 * Defines state of object node.
 * 
 * @author Gilles Cannenterre
 * @since 12 avr. 07
 */
public class ObjectNodeStateSection extends PropertyViewSection {
	
	/**
	 * The subjects composite.
	 */
	private StateComposite stateComposite;
		
	/**
	 * Creates the controls.
	 * 
	 * @param tabbedPropertySheetPage the tabbed property sheet page
	 * @param parent the parent
	 */
	@Override
	public void createControls(Composite parent,
            TabbedPropertySheetPage tabbedPropertySheetPage) {
        super.createControls(parent, tabbedPropertySheetPage);
        // set a grid Layout
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.makeColumnsEqualWidth = true;
        layout.marginWidth = 0; // remove additional spaces
        layout.marginHeight = 0; // remove additional spaces
        parent.setLayout(layout);
        
        GridData data = new GridData();
		data.grabExcessHorizontalSpace = true;
		data.horizontalAlignment = SWT.FILL;
		
		// table for Parameters
        stateComposite = new StateComposite();
        stateComposite.createContent(parent, tabbedPropertySheetPage.getWidgetFactory());
        stateComposite.setLayoutData(data);
    }
    
	/**
	 * Refresh.
	 */
	@Override
	public void refresh() {
    	stateComposite.refresh();
    }

	/**
	 * Sets the input.
	 * 
	 * @param part the part
	 * @param selection the selection
	 */
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
        super.setInput(part, selection);       
    	if (umlElement instanceof ObjectNode) {
    		Element objectNode = new Element((ObjectNode)umlElement);
    		stateComposite.setElement(objectNode);
    	}
    }
	
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.ui.properties.tabbed.PropertyViewSection#dispose()
	 */
	/**
	 * 
	 */
	public void dispose(){
		super.dispose();
		if(stateComposite!=null)
			stateComposite.dispose();
	}
}